﻿@model FTBS.Models.Entities.Schedule

@{
    ViewBag.Title = "Create Schedule";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

<h2 style="font-weight:bold">TẠO MỚI LỊCH CHIẾU PHIM</h2>

@using (Html.BeginForm("CreateSchedule", "Schedule", null, FormMethod.Post,
                              new { enctype = "multipart/form-data", id = "createScheduleForm"}))
{
    @Html.ValidationSummary(true)
    <table class="table striped bordered hovered" style="margin :0px 0px 0px 40px">
        <tr>
            <th>
                Tên Phim
             </th>
            <td style="padding: 0px 10px 0px 20px">
                <div class="input-control select">
                    @Html.DropDownListFor(model => model.FilmId, (SelectList)ViewBag.Film, "--- Chọn tên phim ---")
                    <p style="color: red; font-size: 10pt">@Html.ValidationMessageFor(model => model.FilmId)</p>
                </div>
            </td>
            <th>
                Tên Rạp
            </th>
            <td style="padding: 0px 10px 0px 20px">
                <div class="input-control select">
                    <div>
                        @Html.DropDownListFor(model => model.TheaterId, (SelectList)ViewBag.Theater, "--- Chọn rạp chiếu phim ---", new { id = "cbbTheater" })
                        <p style="color: red; font-size: 10pt">@Html.ValidationMessageFor(model => model.TheaterId)</p>
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <th>
                Phòng
            </th>
            <td style="padding: 0px 10px 0px 20px">
                <div class="input-control select">
                    <div>
                        @Html.DropDownListFor(model => model.RoomId, (SelectList)ViewBag.Room, "--- Chọn phòng chiếu phim ---", new { id = "cbbRoom" })
                        <p style="color: red; font-size: 10pt">@Html.ValidationMessageFor(model => model.RoomId)</p>
                    </div>
                </div>
            </td>
            <th>
                Giờ chiếu
            </th>
            <td>
                <div class="input-control select">
                    <div>
                        @Html.DropDownListFor(model => model.ShowTimeId, (SelectList)ViewBag.ShowTime, "--- Chọn lịch chiếu phim ---", new { id = "cbbShowTime" })
                        <p style="color: red; font-size: 10pt">@Html.ValidationMessageFor(model => model.RoomId)</p>
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <th>
                Khuyến mãi
            </th>
            <td>
                <div class="input-control select">
                    <div>
                        @Html.DropDownListFor(model => model.PromotionId, (SelectList)ViewBag.Promotion, "--- Chọn khuyến mãi cho phim ---")
                        <p style="color: red; font-size: 10pt">@Html.ValidationMessageFor(model => model.PromotionId)</p>
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input class="large info" type="submit" value="Lưu" />
            </td>
        </tr>
    </table>
}
<div>
    @Html.ActionLink("Quay Lại", "ListSchedule")
</div>

<script type="text/javascript">
    $("#cbbTheater").change(function () {
        var valueSelect = $("#cbbTheater").val();
        if (valueSelect > 0) {
            $.ajax({
                type: "POST",
                url: '@Url.Action("GetRoomByTheaterJson", "Schedule")',
                data: { theaterId: $("#cbbTheater > option:selected").attr("value") },
                success: function (data) {
                    var items = [];
                    items.push("<option value='0'>--- Chọn phòng chiếu phim ---</option>");
                    $.each(data, function () {
                        items.push("<option value=" + this.Value + ">" + this.Text + "</option>");
                    });
                    $("#cbbRoom").html(items.join(' '));
                }
            })

            $.ajax({
                type: "POST",
                url: '@Url.Action("GetShowTimeByTheaterJson", "Schedule")',
                data: { theaterId: $("#cbbTheater > option:selected").attr("value") },
                success: function (data) {
                    var items = [];
                    items.push("<option value='0'>--- Chọn lịch chiếu phim ---</option>");
                    $.each(data, function () {
                        items.push("<option value=" + this.Value + ">" + this.Text + "</option>");
                    });
                    $("#cbbShowTime").html(items.join(' '));
                }
            })
        }
    });

</script>
